package com.study.common.convert;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.FillPatternType;


/**
 * @author nizhihao
 * @version 1.0.0
 * @date 2024/4/28 15:17
 */
@Slf4j
public class CellStyleConvert implements Converter<String> {

    @Override
    public WriteCellData<Object> convertToExcelData(String value, ExcelContentProperty contentProperty,
                                                    GlobalConfiguration globalConfiguration) throws Exception {
        WriteCellData<Object> cellData = new WriteCellData<>(value);
        // 创建单元格样式
        WriteCellStyle cellStyle = new WriteCellStyle();

        // 设置背景色
        cellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);

        // 设置字体样式
        WriteFont font = new WriteFont();
        font.setBold(true);
        font.setFontHeightInPoints((short) 12);
        cellStyle.setWriteFont(font);

        cellData.setWriteCellStyle(cellStyle);
        return cellData;
    }

}
